//
//  YTPopupView.h
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/3/10.
//  Copyright © 2017年 YiTu. All rights reserved.
//

#import <UIKit/UIKit.h>

#pragma mark - enum

// YTPopupShowType: 弹出动画
typedef NS_ENUM(NSInteger, YTPopupShowType) {
    YTPopupShowTypeNone = 0,
    YTPopupShowTypeFadeIn,
    YTPopupShowTypeGrowIn,
    YTPopupShowTypeShrinkIn,
    YTPopupShowTypeSlideInFromTop,
    YTPopupShowTypeSlideInFromBottom,
    YTPopupShowTypeSlideInFromLeft,
    YTPopupShowTypeSlideInFromRight,
    YTPopupShowTypeBounceIn,
    YTPopupShowTypeBounceInFromTop,
    YTPopupShowTypeBounceInFromBottom,
    YTPopupShowTypeBounceInFromLeft,
    YTPopupShowTypeBounceInFromRight,
};

// YTPopupDismissType: 消失动画
typedef NS_ENUM(NSInteger, YTPopupDismissType) {
    YTPopupDismissTypeNone = 0,
    YTPopupDismissTypeFadeOut,
    YTPopupDismissTypeGrowOut,
    YTPopupDismissTypeShrinkOut,
    YTPopupDismissTypeSlideOutToTop,
    YTPopupDismissTypeSlideOutToBottom,
    YTPopupDismissTypeSlideOutToLeft,
    YTPopupDismissTypeSlideOutToRight,
    YTPopupDismissTypeBounceOut,
    YTPopupDismissTypeBounceOutToTop,
    YTPopupDismissTypeBounceOutToBottom,
    YTPopupDismissTypeBounceOutToLeft,
    YTPopupDismissTypeBounceOutToRight,
};

// YTPopupHorizontalLayout: 横向布局位置
typedef NS_ENUM(NSInteger, YTPopupHorizontalLayout) {
    YTPopupHorizontalLayoutCustom = 0,
    YTPopupHorizontalLayoutLeft,
    YTPopupHorizontalLayoutLeftOfCenter,
    YTPopupHorizontalLayoutCenter,
    YTPopupHorizontalLayoutRightOfCenter,
    YTPopupHorizontalLayoutRight,
};

// YTPopupVerticalLayout: 纵向布局位置
typedef NS_ENUM(NSInteger, YTPopupVerticalLayout) {
    YTPopupVerticalLayoutCustom = 0,
    YTPopupVerticalLayoutTop,
    YTPopupVerticalLayoutAboveCenter,
    YTPopupVerticalLayoutCenter,
    YTPopupVerticalLayoutBelowCenter,
    YTPopupVerticalLayoutBottom,
};



// YTPopupMaskType: 交互方式
typedef NS_ENUM(NSInteger, YTPopupMaskType) {
    YTPopupMaskTypeNone = 0, // 背景可交互
    YTPopupMaskTypeClear, // 不可交互
    YTPopupMaskTypeDimmed, // 不可交互
};

// YTPopupLayout: 布局，跟CGSize类似
struct YTPopupLayout {
    YTPopupHorizontalLayout horizontal;
    YTPopupVerticalLayout vertical;
};
typedef struct YTPopupLayout YTPopupLayout;

// 布局方法
extern YTPopupLayout YTPopupLayoutMake(YTPopupHorizontalLayout horizontal, YTPopupVerticalLayout vertical);

// 居中
extern const YTPopupLayout YTPopupLayoutCenter;

@interface YTPopupView : UIView

#pragma mark - property

// 你想要显示的view
// 在弹出之前一定要先添加了
// 至少要提供size，位置可以使用上面👆的YTPopupLayout来指定.
// 如不提供YTPopupLayout，默认是居中的
@property (nonatomic, strong) UIView* contentView;

// 显示动画，默认是shrink in
@property (nonatomic, assign) YTPopupShowType showType;

// 消失动画，默认是shrink out
@property (nonatomic, assign) YTPopupDismissType dismissType;

// 蒙版，默认是dimmed
@property (nonatomic, assign) YTPopupMaskType maskType;

// 蒙版透明度，默认是0.5
@property (nonatomic, assign) CGFloat dimmedMaskAlpha;

// 点击蒙版可消失，默认YES
@property (nonatomic, assign) BOOL shouldDismissOnBackgroundTouch;

// 点击contenview消失，默认NO
@property (nonatomic, assign) BOOL shouldDismissOnContentTouch;

// 显示后回调
@property (nonatomic, copy) void (^didFinishShowingCompletion)();

// 将要消失回调
@property (nonatomic, copy) void (^willStartDismissingCompletion)();

// 消失后回调
@property (nonatomic, copy) void (^didFinishDismissingCompletion)();

#pragma mark - method

/**
 显示，类方法

 @param contentView 内容视图
 @return instencetype
 */
+ (YTPopupView *)popupWithContentView:(UIView*)contentView;

/**
 显示，类方法

 @param contentView 内容视图
 @param showType 显示
 @param dismissType 消失
 @param maskType 蒙版
 @param shouldDismissOnBackgroundTouch 蒙版可交互
 @param shouldDismissOnContentTouch 内容可交互
 @return intancetype
 */
+ (YTPopupView *)popupWithContentView:(UIView *)contentView
                         showType:(YTPopupShowType)showType
                      dismissType:(YTPopupDismissType)dismissType
                         maskType:(YTPopupMaskType)maskType
         dismissOnBackgroundTouch:(BOOL)shouldDismissOnBackgroundTouch
            dismissOnContentTouch:(BOOL)shouldDismissOnContentTouch;

// 让窗体全部消失，相当于一个清理的方法
+ (void)dismissAllPopups;

// 不需要制定显示的位置
// 默认显示在中心
- (void)show;
// 指定位置显示
- (void)showWithLayout:(YTPopupLayout)layout;
// 指定显示时间
- (void)showWithDuration:(NSTimeInterval)duration;
// 时间和位置同时指定
- (void)showWithLayout:(YTPopupLayout)layout duration:(NSTimeInterval)duration;
// 下面👇的俩方法都是可以指定中心点来显示
- (void)showAtCenter:(CGPoint)center inView:(UIView*)view;
- (void)showAtCenter:(CGPoint)center inView:(UIView *)view withDuration:(NSTimeInterval)duration;

// 消失，默认animated = YES
- (void)dismiss:(BOOL)animated;

#pragma mark  - 子类实现

@property (nonatomic, strong, readonly) UIView *backgroundView;
@property (nonatomic, strong, readonly) UIView *containerView;
@property (nonatomic, assign, readonly) BOOL isBeingShown;
@property (nonatomic, assign, readonly) BOOL isShowing;
@property (nonatomic, assign, readonly) BOOL isBeingDismissed;

- (void)willStartShowing;
- (void)didFinishShowing;
- (void)willStartDismissing;
- (void)didFinishDismissing;

@end

#pragma mark - UIView Category

@interface UIView(KLCPopup)
- (void)forEachPopupDoBlock:(void (^)(YTPopupView *popup))block;
- (void)dismissPresentingPopup;
@end
